Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation endpoint to Igbo API #812

Merged
merged 20 commits into from
Nov 1, 2024
Merged

Conversation

ebubae
Copy link
Collaborator

@ebubae ebubae commented Oct 9, 2024

Describe your changes

This PR updates the IgboAPI with a new endpoint to do Igbo-to-English text translation.

Motivation and Context

We're constantly trying to improve our AI product offering to include more useful Igbo technology. This now includes a machine translation endpoint served by Nkọwa okwu team.

How Has This Been Tested?

Tests can be found in src/controllers/__tests__/translation.test.ts

@ebubae ebubae requested a review from ijemmao October 9, 2024 18:23
src/config.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@ijemmao ijemmao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks really goooooood! amazing first PR, you got like 90% off jump

src/config.ts Show resolved Hide resolved
const ONE_DAY = 24 * 60 * 60 * 1000;
const REQUESTS_PER_MS_TRANSLATION = 5;

const translationRateLimiter: MiddleWare = rateLimit({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we want rate limiting to prevent too many subsequent requests in period of time rather than limiting the total number of requests that can be made. the logic that's responsible for capping the total number of requests that the current user can make with the API Key lives in authorizeDeveloperUsage.

i do think we want a rate limiter in general - we can talk about that more.

also, can we have this rate limiter not be applied if the incoming request comes from our official platforms? we would want to check to see if the X-API-Key header is equal to MAIN_KEY which is in config.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion, I made this ticket for us to push a fix for rate limiting in a separate PR #814

src/routers/routerV2.ts Outdated Show resolved Hide resolved
src/routers/routerV2.ts Outdated Show resolved Hide resolved
src/controllers/translation.ts Outdated Show resolved Hide resolved
src/controllers/translation.ts Outdated Show resolved Hide resolved
src/controllers/translation.ts Outdated Show resolved Hide resolved
src/controllers/translation.ts Show resolved Hide resolved
src/routers/routerV2.ts Outdated Show resolved Hide resolved
src/config.ts Show resolved Hide resolved
Comment on lines 14 to 21
// TODO: add rate limiting with upstash
// const ONE_DAY = 24 * 60 * 60 * 1000;
// const REQUESTS_PER_MS_TRANSLATION = 5;

// const translationRateLimiter: MiddleWare = rateLimit({
// windowMs: ONE_DAY,
// max: REQUESTS_PER_MS_TRANSLATION,
// });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can delete this comment since you have a corresponding GitHub issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

});
};

const getApiTypeFromRoute = (route: string): ApiType => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you add a comment for this function?

body: { igbo: 'aka' },
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'main_key',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should import MAIN_KEY instead of hardcoding 'main_key'

data: { igbo: 'aka'.repeat(100) },
});
await getTranslation(req, res, next);
expect(next).toHaveBeenCalled();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to check the error message here too so we know which error was thrown?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now doing that check!

data: { igbo: '' },
});
await getTranslation(req, res, next);
expect(next).toHaveBeenCalled();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here

ijemmao
ijemmao previously approved these changes Oct 24, 2024
Copy link
Collaborator

@ijemmao ijemmao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!! Just a few nit comments about spacing, using variables, and adding comments - really excited for this 🚀

import { IGBO_TO_ENGLISH_API, MAIN_KEY } from '../config';

interface TranslationMetadata {
igbo: string;
Copy link
Collaborator

@ijemmao ijemmao Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want to have a schema similar to something like the following:

Suggested change
igbo: string;
text: string;
sourceLanguageCode: LanguageEnum;
destinationLanguageCode: LanguageEnum;

LanguageEnum would include he ISO language codes, so for Igbo it would be ibo. LanguageEnum exists in our codebase right now. This way we can avoid the potential case where we need to add more fields when we want to support more languages

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now validating the request body. For now, the call to the ML endpoint won't change but that's more of an implementation detail.

@ebubae
Copy link
Collaborator Author

ebubae commented Oct 31, 2024

I've added the schema changes we discussed. Also some new validation for the schema values as well as new tests for the extra validation. Let me know if any more needs to be done!

@ebubae ebubae requested a review from ijemmao October 31, 2024 17:45
Copy link
Collaborator

@ijemmao ijemmao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excited!!! this is going to make for a great demo

@ijemmao ijemmao merged commit 0ac1b9d into master Nov 1, 2024
4 checks passed
@ijemmao ijemmao deleted the ec/translation-endpoint branch November 1, 2024 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants